package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.SectionImpl;

/**
 * Servlet implementation class DeleteSection
 */
@WebServlet(name="DeleteSection",
urlPatterns= {"/servlet/DeleteSection"},
loadOnStartup = 1)
public class DeleteSection extends HttpServlet {
	private static final long serialVersionUID = 1L;
	int n;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteSection() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//response.getWriter().append("Served at: ").append(request.getContextPath());
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//doGet(request, response);
		response.setContentType("text/html,charset=utf-8");
		request.setCharacterEncoding("utf-8");
		String ck[]=request.getParameterValues("ck");
		//System.out.println(checkbox[0]);
		//int[] checkboxs=new int[checkbox.length];
		//for(int j=0;j<checkbox.length;j++) {
		//	checkboxs[j]=Integer.parseInt(checkbox[j]);
		//}
		SectionImpl sectionbean=new SectionImpl();
		for(int i=0;i<ck.length;i++) {
			
			n=sectionbean.delete(ck[i]);
			
			}
		if(n>0) {
			request.getRequestDispatcher("/section.jsp").forward(request, response);
		}else {
			request.getRequestDispatcher("/error.jsp").forward(request, response);
		}
		}
		
	}


